/*
 * vector.cpp
 *
 *  Created on: 05.11.2011
 *      Author: ignacio
 */




#include "vector.h"


#include <cmath>
using std::sqrt;
using std::sin;
using std::cos;
using std::pow;
using std::atan2;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;


namespace neurignacio{

	ostream& operator<<(ostream& out, const ID_fVector3& vector)
	{
		out << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]";
	}

	float sqrt(const ID_Angle& theta, const angleUnit& unit)
	{
		if (unit==degrees)
			return std::sqrt(theta.to_degrees());
		else
			return std::sqrt(theta.to_radians());
	}

	float sin(const ID_Angle& theta)
	{
		return std::sin(theta.to_radians());
	}

	float cos(const ID_Angle& theta)
	{
		return std::cos(theta.to_radians());
	}
	Vector3 pow(const Vector3& vector, const float& exponent)
	{
		return Vector3(std::pow(vector.x,exponent), std::pow(vector.y,exponent), std::pow(vector.z,exponent));
	}
	ID_Angle pow(const ID_Angle& theta, const float& exponent)
	{
		return ID_Angle(std::pow(theta.to_radians(), exponent), radians);
	}
	float pow(const float& base, const float& exponent)
	{
		return std::pow(base, exponent);
	}

	ID_Angle abs(const ID_Angle& theta)
	{
		real rad=theta.to_radians()<0? -theta.to_radians() : theta.to_radians();
		return ID_Angle(rad, radians);
	}

	ID_Angle atan2(const float& y, const float& x)
	{
		return ID_Angle(std::atan2(y, x), radians);
	}

	ID_Angle ID_fVector3::angleXZ() const
	{
		return ID_Angle(std::atan2(z,x), radians);
	}

	ID_Angle ID_fVector3::angle() const
	// Alias for angleXZ()
	{
		return angleXZ();
	}

	void ID_fVector3::random(unsigned int seed)
	// Generates random vector in range from -1.0 to 1.0
	{
	  /* initialize random seed: */
	  if (!seed) seed=time(NULL);
	  srand(seed);
	  x = static_cast<real>(2*rand()-RAND_MAX) / RAND_MAX;
	  y = static_cast<real>(2*rand()-RAND_MAX) / RAND_MAX;
	  z = static_cast<real>(2*rand()-RAND_MAX) / RAND_MAX;
	}

} // end namespace neurignacio
